<!--
  Copyright 2013-2019 the original author or authors.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- id is used for auto focus, see storage.js -->
<div class="card" id="storageConfigCard">
  <div class="card-header">
    <h2>Storage</h2>
  </div>
  <div class="card-body">
    <div ng-include src="'template/gt-loading-overlay.html'"></div>
    <div ng-include src="'template/gt-http-error-overlay.html'"></div>
    <!-- not using gt-form-autofocus-on-first-input in order to handle special case #rollup-detail-capped-size
         and trace-detail-capped-size urls (see storage.js) -->
    <div ng-form
         name="formCtrl">
      <fieldset class="gt-fieldset"
                ng-if="!layout.central">
        <legend class="gt-legend">
          data.h2.db
        </legend>
        <div gt-form-group
             gt-label="Response time and JVM gauge data (1&nbsp;minute&nbsp;aggregates)"
             gt-model="page.rollupExpirationDays[0]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            The data that is displayed under the transaction response time tab and on the JVM gauge screen is collected
            continuously and stored at 1 minute intervals. This setting defines how long to retain these 1 minute
            aggregates. (this setting also applies to the 5 second gauge data)
          </div>
        </div>
        <div gt-form-group
             gt-label="Response time and JVM gauge data (5&nbsp;minute&nbsp;aggregates)"
             gt-model="page.rollupExpirationDays[1]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Response time and JVM gauge data is rolled up at 5 minute intervals.
            This setting defines how long to retain these 5 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Response time and JVM gauge data (30&nbsp;minute&nbsp;aggregates)"
             gt-model="page.rollupExpirationDays[2]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Response time and JVM gauge data is rolled up again at 30 minute intervals.
            This setting defines how long to retain these 30 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Response time and JVM gauge data (4&nbsp;hour&nbsp;aggregates)"
             gt-model="page.rollupExpirationDays[3]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Response time and JVM gauge data is rolled up again at 4 hour intervals.
            This setting defines how long to retain these 4 hour aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Trace data"
             gt-model="page.traceExpirationDays"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            This setting defines how long to retain the trace points and trace header data that is displayed under the
            transaction traces tab.
          </div>
        </div>
        <div gt-form-group
             gt-label="Full query text"
             gt-model="page.fullQueryTextExpirationDays"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            This setting defines how long to retain the full query text that is displayed under the transaction queries
            tab. The truncated query text and query stats are retained according to *.capped.db settings below.
          </div>
        </div>
      </fieldset>
      <fieldset class="gt-fieldset"
                ng-if="!layout.central">
        <legend class="gt-legend">
          *.capped.db
        </legend>
        <div gt-form-group
             gt-label="Query, service call and profile data (1&nbsp;minute&nbsp;aggregates)"
             gt-model="config.rollupCappedDatabaseSizesMb[0]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="MB"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8"
             class="gt-rollup-capped-database-size">
          <div class="help-block">
            The data that is displayed under the transaction queries, service calls and continuous profiling tabs is
            collected continuously and stored at 1 minute intervals. This setting defines how long to retain these 1
            minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Query, service call and profile data (5&nbsp;minute&nbsp;aggregates)"
             gt-model="config.rollupCappedDatabaseSizesMb[1]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="MB"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Query, service call and continuous profiling data is rolled up at 5 minute intervals.
            This setting defines the size of the capped data file used to store these 5 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Query, service call and profile data (30&nbsp;minute&nbsp;aggregates)"
             gt-model="config.rollupCappedDatabaseSizesMb[2]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="MB"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Query, service call and continuous profiling data is rolled up again at 30 minute intervals.
            This setting defines the size of the capped data file used to store these 30 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Query, service call and profile data (4&nbsp;hour&nbsp;aggregates)"
             gt-model="config.rollupCappedDatabaseSizesMb[3]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="MB"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Query, service call and continuous profiling data is rolled up again at 4 hour intervals.
            This setting defines the size of the capped data file used to store these 4 hour aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="Trace detail data"
             gt-model="config.traceCappedDatabaseSizeMb"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="MB"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8"
             class="gt-trace-capped-database-size">
          <div class="help-block">
            This setting defines the size of the capped data file used to store the trace detail data
            (trace entries, trace query stats and trace profiles).
          </div>
        </div>
      </fieldset>
      <fieldset class="gt-fieldset"
                ng-if="layout.central">
        <legend class="gt-legend">
          Response time and JVM gauge data
        </legend>
        <div gt-form-group
             gt-label="1&nbsp;minute&nbsp;aggregates"
             gt-model="page.rollupExpirationDays[0]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            The data that is displayed under the transaction response time tab and on the JVM gauge screen is collected
            continuously by the agents and sent to the central collector (and stored) at 1 minute intervals.
            This setting defines how long to retain these 1 minute aggregates.
            (this setting also applies to the 5 second gauge data)
          </div>
        </div>
        <div gt-form-group
             gt-label="5&nbsp;minute&nbsp;aggregates"
             gt-model="page.rollupExpirationDays[1]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Response time and JVM gauge data is rolled up at 5 minute intervals.
            This setting defines how long to retain these 5 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="30&nbsp;minute&nbsp;aggregates"
             gt-model="page.rollupExpirationDays[2]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Response time and JVM gauge data is rolled up again at 30 minute intervals.
            This setting defines how long to retain these 30 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="4&nbsp;hour&nbsp;aggregates"
             gt-model="page.rollupExpirationDays[3]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Response time and JVM gauge data is rolled up again at 4 hour intervals.
            This setting defines how long to retain these 4 hour aggregates.
          </div>
        </div>
      </fieldset>
      <fieldset class="gt-fieldset"
                ng-if="layout.central">
        <legend class="gt-legend">
          Query and service call data
        </legend>
        <div gt-form-group
             gt-label="1&nbsp;minute&nbsp;aggregates"
             gt-model="page.queryAndServiceCallRollupExpirationDays[0]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            The data that is displayed under the transaction queries and service calls tabs is collected continuously by
            the agents and sent to the central collector (and stored) at 1 minute intervals.
            This setting defines how long to retain these 1 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="5&nbsp;minute&nbsp;aggregates"
             gt-model="page.queryAndServiceCallRollupExpirationDays[1]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Query and service call data is rolled up at 5 minute intervals.
            This setting defines how long to retain these 5 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="30&nbsp;minute&nbsp;aggregates"
             gt-model="page.queryAndServiceCallRollupExpirationDays[2]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Query and service call data is rolled up again at 30 minute intervals.
            This setting defines how long to retain these 30 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="4&nbsp;hour&nbsp;aggregates"
             gt-model="page.queryAndServiceCallRollupExpirationDays[3]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Query and service call data is rolled up again at 4 hour intervals.
            This setting defines how long to retain these 4 hour aggregates.
          </div>
        </div>
      </fieldset>
      <fieldset class="gt-fieldset"
                ng-if="layout.central">
        <legend class="gt-legend">
          Profile data
        </legend>
        <div gt-form-group
             gt-label="1&nbsp;minute&nbsp;aggregates"
             gt-model="page.profileRollupExpirationDays[0]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            The data that is displayed under the transaction continuous profiling tab is collected continuously by the
            agents and sent to the central collector (and stored) at 1 minute intervals.
            This setting defines how long to retain these 1 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="5&nbsp;minute&nbsp;aggregates"
             gt-model="page.profileRollupExpirationDays[1]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Profile data is rolled up at 5 minute intervals.
            This setting defines how long to retain these 5 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="30&nbsp;minute&nbsp;aggregates"
             gt-model="page.profileRollupExpirationDays[2]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Profile data is rolled up again at 30 minute intervals.
            This setting defines how long to retain these 30 minute aggregates.
          </div>
        </div>
        <div gt-form-group
             gt-label="4&nbsp;hour&nbsp;aggregates"
             gt-model="page.profileRollupExpirationDays[3]"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            Profile data is rolled up again at 4 hour intervals.
            This setting defines how long to retain these 4 hour aggregates.
          </div>
        </div>
      </fieldset>
      <fieldset class="gt-fieldset"
                ng-if="layout.central">
        <legend class="gt-legend">
          Trace data
        </legend>
        <div gt-form-group
             gt-label="Trace data"
             gt-model="page.traceExpirationDays"
             gt-number="true"
             gt-pattern="pattern.integer"
             gt-required="loaded"
             gt-disabled="!layout.adminEdit"
             gt-width="7em"
             gt-addon="days"
             gt-col-class1="col-xl-4"
             gt-col-class2="col-xl-8">
          <div class="help-block">
            This setting defines how long to retain trace data. This includes individual traces and error message data.
          </div>
        </div>
      </fieldset>
      <div class="form-group row gt-form-buttons-below-fieldset"
           ng-if="layout.adminEdit || layout.offlineViewer">
        <div class="offset-xl-4 col-xl-8">
          <div gt-button-group>
            <div gt-button
                 gt-label="Save changes"
                 gt-click="save(deferred)"
                 gt-validate-form="formCtrl"
                 ng-if="layout.adminEdit"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Update TWCS window sizes"
                 gt-click="updateCassandraTwcsWindowSizes(deferred)"
                 gt-btn-class="btn-secondary"
                 gt-dont-validate-form="true"
                 gt-confirm-header="Update TWCS window sizes?"
                 gt-confirm-body="This could trigger a lot of window major compactions."
                 ng-if="layout.adminEdit && layout.central"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Defrag H2 data"
                 gt-click="defragH2Data(deferred)"
                 gt-btn-class="btn-secondary"
                 gt-dont-validate-form="true"
                 gt-confirm-header="Defrag H2 data?"
                 gt-confirm-body="This could take several minutes depending on the H2 data file size, during which time Glowroot will not capture any new data."
                 ng-if="layout.adminEdit && !layout.central"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Compact H2 data"
                 gt-click="compactH2Data(deferred)"
                 gt-btn-class="btn-secondary"
                 gt-dont-validate-form="true"
                 gt-confirm-header="Compact H2 data?"
                 gt-confirm-body="This could take several minutes depending on the H2 data file size, during which time Glowroot will not capture any new data."
                 ng-if="layout.adminEdit && !layout.central"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Analyze H2 disk space"
                 gt-click="analyzeH2DiskSpace(deferred)"
                 gt-btn-class="btn-secondary"
                 gt-dont-validate-form="true"
                 gt-confirm-header="Analyze H2 disk space?"
                 gt-confirm-body="This could take several minutes depending on the H2 data file size, during which time Glowroot data capture will be impacted."
                 ng-if="layout.adminEdit && !layout.central"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Analyze trace counts"
                 gt-click="analyzeTraceCounts(deferred)"
                 gt-btn-class="btn-secondary"
                 gt-dont-validate-form="true"
                 gt-confirm-header="Analyze trace counts?"
                 gt-confirm-body="This could take several minutes depending on the number of traces, during which time Glowroot data capture will be impacted."
                 ng-if="layout.adminEdit && !layout.central"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Delete all data"
                 gt-click="deleteAllStoredData(deferred)"
                 gt-btn-class="btn-danger"
                 gt-dont-validate-form="true"
                 gt-confirm-header="Delete all data?"
                 gt-confirm-body="This will delete all captured data, including aggregated transaction data, traces and gauge data."
                 ng-if="layout.adminEdit && !layout.central"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Defrag H2 data"
                 gt-click="defragH2Data(deferred)"
                 gt-btn-class="btn-secondary"
                 ng-if="layout.offlineViewer"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Compact H2 data"
                 gt-click="compactH2Data(deferred)"
                 gt-btn-class="btn-secondary"
                 ng-if="layout.offlineViewer"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Analyze H2 disk space"
                 gt-click="analyzeH2DiskSpace(deferred)"
                 gt-btn-class="btn-secondary"
                 ng-if="layout.offlineViewer"
                 class="d-inline-block">
            </div>
            <div gt-button
                 gt-label="Analyze trace counts"
                 gt-click="analyzeTraceCounts(deferred)"
                 gt-btn-class="btn-secondary"
                 ng-if="layout.offlineViewer"
                 class="d-inline-block">
            </div>
          </div>
          <div class="help-block" ng-if="layout.central">
            Updated expiration settings only apply to data collected from this point forward. Existing data is still
            tagged with the expiration settings in effect at the time the data was captured since using
            <a href="https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_expire_c.html">Cassandra TTL</a>
            to implement expiration.
          </div>
          <div class="help-block" ng-if="layout.central">
            <a href="http://cassandra.apache.org/doc/latest/operating/compaction.html#time-window-compactionstrategy">
              Cassandra TWCS</a> window sizes are calculated using the TTL for the table divided by 24, so that the
            table will have approximately 24 windows.
          </div>
        </div>
      </div>
      <div ng-if="showH2DiskSpaceAnalysis">
        <div style="margin-top: 40px;">
          <span style="font-weight: bold; margin-left: 8px;">H2 data file size:</span> {{h2DataFileSize | gtBytes}}
        </div>
        <table class="table"
               style="table-layout: fixed; margin-top: 30px;">
          <thead>
          <tr>
            <th style="width: 50%;">
              Table name
            </th>
            <th style="width: 25%;">
              Total bytes
            </th>
            <th style="width: 25%;">
              Row count
            </th>
          </tr>
          </thead>
          <tbody>
          <tr ng-repeat="analyzedH2Table in analyzedH2Tables">
            <td>
              {{analyzedH2Table.name}}
            </td>
            <td>
              {{analyzedH2Table.bytes | number}}
            </td>
            <td>
              {{analyzedH2Table.rows | number}}
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <div ng-if="showTraceCountAnalysis">
        <table class="table"
               style="table-layout: fixed; margin-top: 40px;"
               ng-if="analyzedTraceOverallCounts.length > 1">
          <thead>
          <tr style="padding-top: 10px;">
            <th colspan="3" style="font-size: 18px; font-weight: 600; text-align: center;">By transaction type</th>
          </tr>
          <tr>
            <th>
              Transaction type
            </th>
            <th>
              Traces captured
            </th>
            <th>
              Traces captured because they were flagged as errors
            </th>
          </tr>
          </thead>
          <tbody>
          <tr ng-repeat="analyzedTraceOverallCount in analyzedTraceOverallCounts">
            <td>
              {{analyzedTraceOverallCount.transactionType}}
            </td>
            <td>
              {{analyzedTraceOverallCount.count | number}}
            </td>
            <td>
              {{analyzedTraceOverallCount.errorCount | number}}
            </td>
          </tr>
          </tbody>
        </table>
        <table class="table"
               style="table-layout: fixed; margin-top: 40px;">
          <thead>
          <tr ng-if="analyzedTraceOverallCounts.length > 1">
            <th colspan="4" style="font-size: 18px; font-weight: 600; text-align: center;">By transaction name</th>
          </tr>
          <tr>
            <th style="width: 20%;">
              Transaction type
            </th>
            <th style="width: 40%;">
              Transaction name
            </th>
            <th style="width: 20%;">
              Traces captured
            </th>
            <th style="width: 20%;">
              Traces captured because they were flagged as errors
            </th>
          </tr>
          </thead>
          <tbody>
          <tr ng-repeat="analyzedTraceCount in analyzedTraceCounts">
            <td>
              {{analyzedTraceCount.transactionType}}
            </td>
            <td class="gt-break-word">
              {{analyzedTraceCount.transactionName}}
            </td>
            <td>
              {{analyzedTraceCount.count | number}}
            </td>
            <td>
              {{analyzedTraceCount.errorCount | number}}
            </td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<!-- each page with confirmation dialog needs its own confirmation dom so that it is deleted on $destroy -->
<div ng-include="'template/gt-confirmation.html'"></div>
